-------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\brf22\Dropbox\my_research\teranks\RESTAT\retennesseestar\star_example_final
> .log
  log type:  text
 opened on:   8 Feb 2017, 13:40:18

. use STAR_Students;
(Written by R.              )

. gen free_lunch=gkfreelunch==1 if gkfreelunch~=.;
(5,301 missing values generated)

.   label variable free_lunch "Eligible for free lunch in kindergarten";

.   gen treat=gkclasstype==1 if gkclasstype~=.;
(5,276 missing values generated)

.   label variable treat "Assigned to small class in kindergarten";

.   **Let's keep only those observations that have all of the data
> **we need.;
. keep if treat~=. & free_lunch~=. & g1tmathss~=.;
(7,193 observations deleted)

.   **Let's look at first grade math scores.;
. sort treat g1tmathss;

. sum free_lunch;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  free_lunch |      4,408    .4450998    .4970332          0          1

. **Note there are 1368 treated observations and 3040 control observations;
. by treat: gen rank=_n;

. gen treat_pct=rank/1368 if treat==1;
(3,040 missing values generated)

.   label variable treat_pct "rank in treated distribution";

. **There are some ties that we should clump together.;
. egen tmpvar=mean(treat_pct), by(g1tmathss);
(17 missing values generated)

. replace treat_pct=tmpvar if treat==1;
(1,338 real changes made)

. drop tmpvar;

.     gen control_pct=rank/3040 if treat==0;
(1,368 missing values generated)

.   label variable control_pct "rank in control distribution";

.   **Dealing with ties again.;
. egen tmpvar=mean(control_pct), by(g1tmathss);
(1 missing value generated)

. replace control_pct=tmpvar if treat==0;
(3,004 real changes made)

. drop tmpvar;

.      gen pct=treat_pct if treat==1;
(3,040 missing values generated)

. replace pct=control_pct if treat==0;
(3,040 real changes made)

. **Formal tests.;
. ranktest g1tmathss treat treat free_lunch;

Abadie-kappa Weighted Least Squares


             |     coeff         se 
-------------+----------------------
       treat | -.0236912   .0122072 
  free_lunch | -.2081006   .0099888 
    __000006 |  .0538477   .0183263 
    constant |  .6048058   .0065315 


Rank Similarity Test Results

test statistic = 8.633

p-value = 0.00

. **Now let's look at some pictures.;
. gen bin=ceil(pct*10)/.10;

. tab treat free_lunch;

  Assigned |
  to small |
  class in |   Eligible for free
kindergart | lunch in kindergarten
        en |         0          1 |     Total
-----------+----------------------+----------
         0 |     1,680      1,360 |     3,040 
         1 |       766        602 |     1,368 
-----------+----------------------+----------
     Total |     2,446      1,962 |     4,408 


. gen treat_freq=1/1368 if treat==1;
(3,040 missing values generated)

.   label variable treat_freq "treatment observations";

. gen control_freq=1/3040 if treat==0;
(1,368 missing values generated)

.   label variable control_freq "control observations";

. gen treat_freq_high=1/766 if treat==1 & free_lunch==0;
(3,642 missing values generated)

.   label variable treat_freq_high "treatment observations with high income";

. gen control_freq_high=1/1680 if treat==0 & free_lunch==0;
(2,728 missing values generated)

.   label variable control_freq_high "control observations with high income";

. gen treat_freq_low=1/602 if treat==1 & free_lunch==1;
(3,806 missing values generated)

.   label variable treat_freq_low "treatment observations with low income";

. gen control_freq_low=1/1360 if treat==0 & free_lunch==1;
(3,048 missing values generated)

.   label variable control_freq_low "control observations with low income";

.   graph bar (sum) control_freq_low control_freq_high, over(bin) bar(1, color(black))
>   bar(2, color(gray)) legend(subtitle("{stSerif}Fraction in Quantile of Control Outcome Distrib
> ution")
>   label(1 "{stSerif}Lower Income")
>   label(2 "{stSerif}Higher Income"))
>   title("{stSerif}Rank Distribution in Control Distribution by Family" "{stSerif}Income (STAR E
> xample)", color(black))
>   saving(control_high_low_comp_STAR, replace);
(file control_high_low_comp_STAR.gph saved)

. graph export control_high_low_comp_STAR.pdf, as(pdf) replace;
(file control_high_low_comp_STAR.pdf written in PDF format)

. graph bar (sum) control_freq_low treat_freq_low, over(bin) bar(1, color(black))
>   bar(2, color(gray)) legend(subtitle("{stSerif}Fraction in Quantile of Outcome Distribution")
>   label(1 "{stSerif}Control Group")
>   label(2 "{stSerif}Treatment Group"))
>   title("{stSerif}Rank Distribution of Subjects with Lower Family Income" "{stSerif}by Treatmen
> t Status (STAR Example)", color(black))
>   saving(treat_control_low_comp_STAR, replace);
(file treat_control_low_comp_STAR.gph saved)

. graph export treat_control_low_comp_STAR.pdf, as(pdf) replace;
(file treat_control_low_comp_STAR.pdf written in PDF format)

. 
end of do-file

. display _N
4408

. use STAR_students
no; data in memory would be lost
r(4);

. use STAR_students,clear
(Written by R.              )

. dispay _N
command dispay is unrecognized
r(199);

. display _N
11601

